Passed
Push — master ( c5754d...f173b7 )
by Darío
05:12
created

workflow.js ➔ $   A

Complexity

Conditions 1
Paths 32

Size

Total Lines 60
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 35
c 3
b 0
f 0
nc 32
nop 0
dl 0
loc 60
rs 9.0399

2 Functions

Rating   Name   Duplication   Size   Complexity  
A workflow.js ➔ ... ➔ $(ꞌbodyꞌ).delegate(ꞌ.btn-remove-worksheetꞌ) 0 9 1
A workflow.js ➔ ... ➔ $(ꞌbodyꞌ).delegate(ꞌ.btn-new-worksheetꞌ) 0 45 4

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
$(function(){
2
3
    $("body").delegate(".btn-new-worksheet", "click", function(event)
4
    {
5
        event.preventDefault();
6
7
        var id_conn   = $(this).attr('data-id');
8
        var conn_name = $(this).attr('data-name');
9
10
        var call = eval($(this).attr('data-callback')) || {};
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
11
12
        call.success = call.success || new Function();
0 ignored issues
show
Performance Best Practice introduced by
Using new Function() to create a function is slow and difficult to debug. Such functions do not create a closure. Consider using another way to define your function.
Loading history...
13
        call.before  = call.before  || new Function();
0 ignored issues
show
Performance Best Practice introduced by
Using new Function() to create a function is slow and difficult to debug. Such functions do not create a closure. Consider using another way to define your function.
Loading history...
14
        call.error   = call.error   || new Function();
0 ignored issues
show
Performance Best Practice introduced by
Using new Function() to create a function is slow and difficult to debug. Such functions do not create a closure. Consider using another way to define your function.
Loading history...
15
16
        var d = new Date();
17
        var n = d.getTime();
18
19
        var title = $("#worksheet-collector .worksheet-item-title").last().clone();
20
21
        if (title.hasClass('active'))
22
            title.removeClass('active');
23
24
        var other_tabs = $("div[data-tab][data-conn='" + id_conn + "']");
25
26
        var tab_index = (other_tabs.length) ? parseInt(other_tabs.last().attr('data-tab-index')) + 1 : 1;
27
28
        title.html(conn_name + "~" + tab_index + "&nbsp; <button class='ui small compact basic button btn-remove-worksheet'>x</button>").attr('data-tab', n);
29
30
        $("#worksheet-collector .worksheet-item-title").last().parent().append(title);
31
32
        var content = $("#worksheet-collector .worksheet-item-content").last().clone();
33
        content.empty().attr('data-conn', id_conn);
34
        content.empty().attr('data-tab-index', tab_index);
35
36
        $("#worksheet-collector .worksheet-item-content").last().parent().append(content);
37
38
        if (content.hasClass('active'))
39
            content.removeClass('active');
40
41
        content.attr('data-tab', n);
42
        content.load(content.attr("data-resource"), { id: n, conn: id_conn });
43
44
        $('.menu .item').tab();
45
46
        $(title).trigger('click');
47
    });
48
49
    $('.menu .item').tab();
50
51
    $("body").delegate(".btn-remove-worksheet", "click", function(event)
52
    {
53
        event.preventDefault();
54
        event.stopPropagation();
55
56
        var tab = $(this).parent().attr('data-tab');
57
        $("[data-tab='" + tab + "']").remove();
58
        $("a[data-tab='home']").trigger("click");
59
    });
60
});